[TOC]

Data Type

In SIMO, an array can contain elements of the following types:

Type Casting

All entries in an array should have the same data type. In some situations, an operator may produce different data types for different entries in an array. Then, they are automatically casted to the type with the highest precedence. The higher the precedence, the higher the precision.

  1. Complex double
  2. Double
  3. Character
  4. Logical

For example, the polynomial has both double and complex-double roots, as seen from the output below. Hence, r is a complex-double array since complex-double has higher precedence than double. As a result, the real root 4 is stored as a complex number, namely, 4.000 - 0.000i.

Input
p=[1 -2 -6 -8];
r=roots(p)
Output
r = 
-1.0000 - 1.0000i
-1.0000 + 1.0000i
 4.0000 - 0.0000i

Some operators require inputs of specific types. If necessary, the operands are first casted to the required types before performing the operation. For examples:

  1. When a double is added to a logical, the latter is casted to a double. Then, the two doubles are added together to get a double as the output. For example, 0.5 + true gives 1.500.
  2. When a character is multiplied with a logical, the two operands are casted to doubles before performing multiplication. For example, 'a' * (1 > 0) gives 97.
  3. A logical array A is casted to a double array when performing cos(A).

Structure array is not a numeric type. It is just a container of data. Hence, type casting does not work for structure arrays.